package cn.bdqn.service.impl;

import cn.bdqn.dto.Dto;
import cn.bdqn.mapper.*;
import cn.bdqn.pojo.*;
import cn.bdqn.service.HotelMessageService;
import cn.bdqn.util.Page;
import cn.bdqn.vo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HotelMessageServiceImpl implements HotelMessageService {
    @Resource
    private ItripHotelFeatureMapper itripHotelFeatureMapper;
    @Resource
    private ItripHotelTradingAreaMapper itripHotelTradingAreaMapper;
    @Resource
    private ItripHotelMapper itripHotelMapper;

    @Resource
    private ItripLabelDicMapper itripLabelDicMapper;
    @Resource
    private ItripAreaDicMapper itripAreaDicMapper;

    @Resource
    private ItripImageMapper itripImageMapper;

    @Resource
    private ItripCommentMapper  itripCommentMapper;


    @Override
    public Dto selectHotelFeatureAndTrade(Integer hotelId) {
        Dto dto=new Dto();
        if(hotelId==null){
            dto.setCode("10001");
            dto.setMsg("城市Id不能为空");
            return dto;
        }
        List<ItripHotelFeature> list1=itripHotelFeatureMapper.selectFeatureByHotelId(hotelId);
        List<String> list11=new ArrayList<>(0);
        List<String> list22=new ArrayList<>(0);
        for(ItripHotelFeature feature:list1){
            String featureName=itripLabelDicMapper.selectByPrimaryKey(feature.getFeatureId()).getName();
            list11.add(featureName);
        }
        List<ItripHotelTradingArea> list2=itripHotelTradingAreaMapper.selectTradeByHotelId(hotelId);
        for(ItripHotelTradingArea trade:list2){
            String featureName=itripAreaDicMapper.selectByPrimaryKey(trade.getAreaId()).getName();
            list22.add(featureName);
        }
        dto.setCode("0");
        dto.setMsg("查询到酒店详情");
        ItripHotel itripHotel=itripHotelMapper.selectById(hotelId);
        HotelVideoVO  hotelVideoVO=new HotelVideoVO();
        hotelVideoVO.setHotelFeatureList(list11);
        hotelVideoVO.setTradingAreaNameList(list22);
        hotelVideoVO.setHotelName(itripHotel.getHotelName());
        dto.setData(hotelVideoVO);
        return dto;
    }

    @Override
    public Dto selectHotelImage(Map map) {
        Dto dto=new Dto();
        map.put("type",1);
        List<ItripImage> list=itripImageMapper.selectByTargetId(map);
        List<HotelImage> list1=new ArrayList<>(0);
        for(ItripImage itripImage:list){
            HotelImage hotelImage=new HotelImage();
            hotelImage.setPosition(itripImage.getPosition());
            hotelImage.setImgUrl(itripImage.getImgUrl());
            list1.add(hotelImage);
        }
        dto.setCode("0");
        dto.setMsg("成功找到图片");
        dto.setData(list1);
        return dto;
    }

    @Override
    public Dto selectHotelPolicy(Integer hotelId) {
        Dto dto=new Dto();
        if(hotelId==null){
            dto.setCode("10001");
            dto.setMsg("酒店id不能为空");
            return dto;
        }
        ItripHotelWithBLOBs itripHotel=itripHotelMapper.selectByPrimaryKey(Long.valueOf(hotelId));
        if(itripHotel==null){
            dto.setCode("10001");
            dto.setMsg("查询不到");
            return dto;
        }
        dto.setCode("0");
        dto.setMsg("成功查询到政策");
        ItripSearchPolicyHotelVO itripSearchPolicyHotelVO =new ItripSearchPolicyHotelVO();
        itripSearchPolicyHotelVO.setHotelPolicy(itripHotel.getHotelPolicy());
        dto.setData(itripSearchPolicyHotelVO.getHotelPolicy());
        return dto;
    }

    @Override
    public Dto selectComment(CommentListVO commentListVO) {
        Dto dto=new Dto();
        Long hotelId=commentListVO.getHotelId();
        Integer isHavingImg=commentListVO.getIsHavingImg();
        Integer isOk=commentListVO.getIsOk();
        Integer pageNo=commentListVO.getPageNo();
        Integer pageSize=commentListVO.getPageSize();

        if(isHavingImg==-1){
            isHavingImg=null;
        }
        if(isOk==-1){
            isOk=null;
        }
        Map map=new HashMap();
        map.put("hotelId",hotelId);
        map.put("isHavingImg",isHavingImg);
        map.put("isOk",isOk);
        map.put("pageNo",pageNo);
        map.put("pageSize",pageSize);
        int totil=itripCommentMapper.selectAllMessageCountByHotelId(map);
        Page page=new Page(pageNo,totil,pageSize);
        page.setCommentListVO(commentListVO);
        List<ItripListCommentVO> list=itripCommentMapper.selectAllMessageByHotelId(map);
        page.setRows(list);
        dto.setData(page);
        return dto;
    }

    @Override
    public Dto selectCommentImg(Integer targetId) {
        Dto dto=new Dto();
        Map map=new HashMap();
        if(targetId==null){
            dto.setCode("10001");
            dto.setMsg("酒店id不能为空");
        }
        map.put("targetId",targetId);
        map.put("type",2);
        List<ItripImage> list=itripImageMapper.selectByTargetId(map);
        if(list.size()<0){
            dto.setCode("10001");
            dto.setMsg("没有对应的图片");
            return dto;
        }
        List list1=new ArrayList(0);
        for(ItripImage i:list){
            HotelImage hotelImage=new HotelImage();
            hotelImage.setPosition(i.getPosition());
            hotelImage.setImgUrl(i.getImgUrl());
            list1.add(hotelImage);
        }
        dto.setCode("0");
        dto.setMsg("查询到图片");
        dto.setData(list1);
        return dto;
    }

    @Override
    public Dto selectHotelImg(Integer targetId) {
        Dto dto=new Dto();
        Map map=new HashMap();
        if(targetId==null){
            dto.setCode("10001");
            dto.setMsg("酒店id不能为空");
        }
        map.put("targetId",targetId);
        map.put("type",0);
        List<ItripImage> list=itripImageMapper.selectByTargetId(map);
        List<HotelImage> list1=new ArrayList(0);
        for(ItripImage i:list){
            HotelImage hotelImage=new HotelImage();
            hotelImage.setPosition(i.getPosition());
            hotelImage.setImgUrl(i.getImgUrl());
            list1.add(hotelImage);
        }
        if(list1.size()<0){
            dto.setMsg("找不到对应图片");
            dto.setCode("10001");
            return dto;
        }
        dto.setCode("0");
        dto.setMsg("找到图片");
        dto.setData(list1);
        return dto;
    }
}
